package com.zb.jnlxc.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.ZLHW.base.Form.Page;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.zb.jnlxc.form.JiYaDetail;
import com.zb.jnlxc.form.MiniPageRsp;
import com.zb.jnlxc.model.Admin;
import com.zb.jnlxc.model.Mould;
import com.zb.jnlxc.service.MouldFlowService;

/**
 * Created by Administrator on 2014/9/10.
 */
@Controller
@RequestMapping("/MouldFlowAction")
@SessionAttributes(value = { "user" })
public class MouldFlowAction {
    @Resource
    private MouldFlowService mouldFlowService;

    /**
     * 获取转修任务
     * @return
     */
    @ResponseBody
    @RequestMapping("/loadMouldFixTask")
    public MiniPageRsp loadMouldFixTask(Page page, @ModelAttribute("user") Admin admin) {
        mouldFlowService.loadMouldFixTask(page, admin);
        return new MiniPageRsp(page.getResultData(), page.getTotalClum());
    }

    /**
     * 获取拋排任务
     * @return
     */
    @ResponseBody
    @RequestMapping("/loadMouldPaoPaiTask")
    public MiniPageRsp loadMouldPaoPaiTask(Page page, @ModelAttribute("user") Admin admin) {
        mouldFlowService.loadMouldPaoPaiTask(page);
        return new MiniPageRsp(page.getResultData(), page.getTotalClum());
    }

    /**
     * 获取氮化任务
     * @return
     */
    @ResponseBody
    @RequestMapping("/loadMouldDanHuaTask")
    public MiniPageRsp loadMouldDanHuaTask(Page page, @ModelAttribute("user") Admin admin) {
        mouldFlowService.loadMouldDanHuaTask(page);
        return new MiniPageRsp(page.getResultData(), page.getTotalClum());
    }

    /**
     * 异常模转修处理
     */
    @ResponseBody
    @RequestMapping("/ycmzxcl")
    public void ycmzxcl(Integer mouldFixTaskId, String formData, String nextStep,
                        @ModelAttribute("user") Admin admin) {
        Map<String, String> form = JSONObject.parseObject(formData,
            new TypeReference<Map<String, String>>() {
            });
        mouldFlowService.ycmzxcl(mouldFixTaskId, form, nextStep, admin);
    }

    /**
     * 异常模转修处理
     */
    @ResponseBody
    @RequestMapping("/dhcl")
    public void dhcl(Integer mouldDanHuaTaskId, String formData, String nextStep,
                     @ModelAttribute("user") Admin admin) {
        Map<String, String> form = JSONObject.parseObject(formData,
            new TypeReference<Map<String, String>>() {
            });
        mouldFlowService.dhcl(mouldDanHuaTaskId, form, admin);
    }

    /**
     * 抛排收模处理
     */
    @ResponseBody
    @RequestMapping("/ppsmcl")
    public void ppsmcl(Integer mouldPaoPaiTaskId, String formData, String nextStep,
                       @ModelAttribute("user") Admin admin) {
        Map<String, String> form = JSONObject.parseObject(formData,
            new TypeReference<Map<String, String>>() {
            });
        mouldFlowService.ppsmcl(mouldPaoPaiTaskId, form, nextStep, admin);
    }

    //退模报废处理
    @ResponseBody
    @RequestMapping("/tmbfcl")
    public void tmbfcl(Integer mouldBaoFeiTaskId, String formData, String nextStep,
                       @ModelAttribute("user") Admin admin) {
        Map<String, String> form = JSONObject.parseObject(formData,
            new TypeReference<Map<String, String>>() {
            });
        mouldFlowService.tmbfcl(mouldBaoFeiTaskId, form, nextStep, admin);
    }

    /**
     * 仓库发模
     */
    @ResponseBody
    @RequestMapping("/ckfm")
    public void ckfm(String taskId, String formData, String nextStep,
                     @ModelAttribute("user") Admin admin) {
        Map<String, String> form = JSONObject.parseObject(formData,
            new TypeReference<Map<String, String>>() {
            });
        mouldFlowService.ckfm(taskId, form, admin);
    }

    /**
     * 用于前台获取的模具信息
     * @param taskId
     * @return
     */
    @ResponseBody
    @RequestMapping("/getMouldFlowInfo")
    public Mould getMouldFlowInfo(String taskId) {
        return mouldFlowService.getMouldFlowInfo(taskId);
    }

    /**
     * 挤压班组收模
     */
    @ResponseBody
    @RequestMapping("/jybzsm")
    public void jybzsm(String taskId, @ModelAttribute("user") Admin user, String formData,
                       String nextStep) {
        Map<String, String> form = JSONObject.parseObject(formData,
            new TypeReference<Map<String, String>>() {
            });
        mouldFlowService.jybzsm(taskId, user, form, nextStep);
    }

    /**
     * 挤压试模具使用
     */
    @ResponseBody
    @RequestMapping("/jysmsy")
    public void jysmsy(@ModelAttribute("user") Admin user, Integer mouldId,
                       Integer paichanRecordId, String jiYaDetai, String formData) {
        List<JiYaDetail> jiYaDetails = JSONObject.parseObject(jiYaDetai,
            new TypeReference<List<JiYaDetail>>() {
            });
        Map<String, String> form = JSONObject.parseObject(formData,
            new TypeReference<Map<String, String>>() {
            });
        mouldFlowService.jysmsy(user, mouldId, paichanRecordId, form, jiYaDetails);
    }

    /**
     * 机台选择模具试模
     */
    @ResponseBody
    @RequestMapping("/selectMouldToShiMo")
    public void selectMouldToShiMo(Integer paiChanMouldId) {
        mouldFlowService.selectMouldToShiMo(paiChanMouldId);
    }

    /**
     * 通知收模
     * @param mould
     */
    @ResponseBody
    @RequestMapping("/notifyShouMU")
    public void notifyShouMU(Mould mould, @ModelAttribute("user") Admin admin) {
        mouldFlowService.notifyShouMU(mould, admin);
    }

    /**
     * 通知泡模收模确认
     * @param mould
     */
    @ResponseBody
    @RequestMapping("/notifyPaoMu")
    public void notifyPaoMu(Mould mould, @ModelAttribute("user") Admin admin) {
        mouldFlowService.notifyPaoMu(mould, admin);
    }

    /**
     * 通知报废退模
     * @param mould
     */
    @ResponseBody
    @RequestMapping("/notifyTuiMu")
    public void notifyTuiMu(Mould mould, @ModelAttribute("user") Admin admin) {
        mouldFlowService.notifyTuiMu(mould, admin);
    }

    /**
     * 模具入库提醒
     * @param mould
     */
    @ResponseBody
    @RequestMapping("/notifyStorage")
    public void notifyStorage(Mould mould, @ModelAttribute("user") Admin admin) {
        mouldFlowService.notifyStorage(mould, admin);
    }

    /**
     * 模具入库
     */
    @ResponseBody
    @RequestMapping("/mjrk")
    public void mjrk(String taskId, Admin user, Map map) {
        mouldFlowService.mjrk(taskId, user, map);
    }

    @ResponseBody
    @RequestMapping("/pmsmqr")
    public void pmsmqr(String taskId, Admin user, Map map) {
        mouldFlowService.pmsmqr(taskId, user, map);
    }

    /**
     * 模具入厂验收
     */
    @ResponseBody
    @RequestMapping("/mjrcys")
    public void mjrcys(String taskId, Admin user, String formData, String nextStep) {
        Map<String, String> form = JSONObject.parseObject(formData,
            new TypeReference<Map<String, String>>() {
            });
        mouldFlowService.mjrcys(taskId, user, form, nextStep);
    }

    /**
     * 模具入厂责任人分配
     */
    @ResponseBody
    @RequestMapping("/mjrczrrfp")
    public void mjrczrrfp(String taskId, Admin user, String formData, String nextStep) {
        Map<String, String> form = JSONObject.parseObject(formData,
            new TypeReference<Map<String, String>>() {
            });
        mouldFlowService.mjrczrrfp(taskId, user, form, nextStep);
    }

    /**
     * 模具出厂
     */
    @ResponseBody
    @RequestMapping("/leaveFactory")
    public void leaveFactory(Integer mouldId,String mjqx){
        mouldFlowService.leaveFactory(mouldId, mjqx);
    }
}
